home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / NDK / NDK_1.3 / Read-Me1.3 / Printer1.3 / Driver.Examples / src / epsonX / transfer.c < prev   
Encoding:
C/C++ Source or Header  |  1988-08-01  |  3.0 KB  |  122 lines

  1. /*
  2.     Transfer routine for EpsonX driver.
  3.     David Berezowski - October/87.
  4. */
  5.  
  6. #include <exec/types.h>
  7. #include "../printer/printer.h"
  8. #include "../printer/prtbase.h"
  9. #include "../printer/prtgfx.h"
  10.  
  11. Transfer(PInfo, y, ptr, colors, BufOffset)
  12. struct PrtInfo *PInfo;
  13. UWORD y;        /* row # */
  14. UBYTE *ptr;        /* ptr to buffer */
  15. UWORD *colors;        /* indexes to color buffers */
  16. ULONG BufOffset;    /* used for interleaved printing */
  17. {
  18.     extern struct PrinterData *PD;
  19.     extern struct PrinterExtendedData *PED;
  20.  
  21.     static UWORD bit_table[8] = {128, 64, 32, 16, 8, 4, 2, 1};
  22.     union colorEntry *ColorInt;
  23.     UBYTE *bptr, *yptr, *mptr, *cptr, Black, Yellow, Magenta, Cyan;
  24.     UBYTE *dmatrix, dvalue, threshold;
  25.     UWORD x, width, sx, *sxptr, color, bit, x3;
  26.  
  27.     /* printer non-specific, MUST DO FOR EVERY PRINTER */
  28.     x = PInfo->pi_xpos;
  29.     ColorInt = PInfo->pi_ColorInt;
  30.     sxptr = PInfo->pi_ScaleX;
  31.     width = PInfo->pi_width;
  32.  
  33.     /* printer specific */
  34.     if (PED->ped_YDotsInch == 216) {
  35.         BufOffset *= y % 3;
  36.         y /= 3;
  37.     }
  38.     else if (PED->ped_YDotsInch == 144) {
  39.         BufOffset *= y & 1;
  40.         y /= 2;
  41.     }
  42.     else {
  43.         BufOffset = 0;
  44.     }
  45.     bit = bit_table[y & 7];
  46.     bptr = ptr + colors[0] + BufOffset;
  47.     yptr = ptr + colors[1] + BufOffset;
  48.     mptr = ptr + colors[2] + BufOffset;
  49.     cptr = ptr + colors[3] + BufOffset;
  50.  
  51.     /* pre-compute threshold; are we thresholding? */
  52.     if (threshold = PInfo->pi_threshold) { /* thresholding */
  53.         dvalue = threshold ^ 15;
  54.         bptr += x;
  55.         do { /* for all source pixels */
  56.             /* pre-compute intensity values for Black component */
  57.             Black = ColorInt->colorByte[PCMBLACK];
  58.             ColorInt++;
  59.  
  60.             sx = *sxptr++;
  61.  
  62.             do { /* use this pixel 'sx' times */
  63.                 if (Black > dvalue) {
  64.                     *bptr |= bit;
  65.                 }
  66.                 bptr++; /* done 1 more printer pixel */
  67.             } while (--sx);
  68.         } while (--width);
  69.     }
  70.     else { /* not thresholding, pre-compute ptr to dither matrix */
  71.         dmatrix = PInfo->pi_dmatrix + ((y & 3) << 2);
  72.         if (PD->pd_Preferences.PrintShade == SHADE_GREYSCALE) {
  73.             do { /* for all source pixels */
  74.                 /* pre-compute intensity values for Black */
  75.                 Black = ColorInt->colorByte[PCMBLACK];
  76.                 ColorInt++;
  77.  
  78.                 sx = *sxptr++;
  79.  
  80.                 do { /* use this pixel 'sx' times */
  81.                     if (Black > dmatrix[x & 3]) {
  82.                         *(bptr + x) |= bit;
  83.                     }
  84.                     x++; /* done 1 more printer pixel */
  85.                 } while (--sx);
  86.             } while (--width);
  87.         }
  88.         else { /* color */
  89.             do { /* for all source pixels */
  90.                 /* compute intensity values for each color */
  91.                 Black = ColorInt->colorByte[PCMBLACK];
  92.                 Yellow = ColorInt->colorByte[PCMYELLOW];
  93.                 Magenta = ColorInt->colorByte[PCMMAGENTA];
  94.                 Cyan = ColorInt->colorByte[PCMCYAN];
  95.                 ColorInt++;
  96.  
  97.                 sx = *sxptr++;
  98.  
  99.                 do { /* use this pixel 'sx' times */
  100.                     x3 = x >> 3;
  101.                     dvalue = dmatrix[x & 3];
  102.                     if (Black > dvalue) {
  103.                         *(bptr + x) |= bit;
  104.                     }
  105.                     else  { /* black not rendered */
  106.                         if (Yellow > dvalue) {
  107.                             *(yptr + x) |= bit;
  108.                         }
  109.                         if (Magenta > dvalue) {
  110.                             *(mptr + x) |= bit;
  111.                         }
  112.                         if (Cyan > dvalue) {
  113.                             *(cptr + x) |= bit;
  114.                         }
  115.                     }
  116.                     ++x; /* done 1 more printer pixel */
  117.                 } while (--sx);
  118.             } while (--width);
  119.         }
  120.     }
  121. }
  122.